package com.lill.product.web;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lill.common.component.util.R;
import com.lill.product.model.BaseDiscountModel;
import com.lill.product.model.BaseRoyaltyModel;
import com.lill.product.service.IBaseDiscountService;
import com.lill.product.service.IBaseRoyaltyService;
import com.lill.support.annotation.CurrentUser;
import com.lill.system.model.SysUserEntity;

/**
 * 厂家返利Controller
 *
 * @author lill
 * @date 2021-08-31 11:01:26
 */
@RestController
@RequestMapping("base/allProfits")
public class BaseAllProfitsController {
	
    @Autowired
    private IBaseDiscountService baseDiscountService;
    @Autowired
    private IBaseRoyaltyService baseRoyaltyService;
    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params,@CurrentUser SysUserEntity user) {
    	params.put("companyId", user.getCompanyId());
    	if(StringUtils.isNotEmpty(user.getBranchId())){
    		params.put("branchId", user.getBranchId());
    	}else{
    		params.put("branchIdIsNull", user.getCompanyId());
    	}
    	List<Object> list=new ArrayList<Object>();
        List<BaseDiscountModel> discountList = baseDiscountService.queryList(params);
        if(CollectionUtils.isNotEmpty(discountList)){
        	list.addAll(discountList);
        }
        List<BaseRoyaltyModel> royaltyList = baseRoyaltyService.queryList(params);
        if(CollectionUtils.isNotEmpty(royaltyList)){
        	list.addAll(royaltyList);
        }
        return R.ok().put("list", list);
    }
}
